
/**
  ******************************************************************************
  * @file    eeprom.c
  * @brief   This file provides code for the configuration
  *          of the IIC instances.
  ******************************************************************************
  * @attention
  *
  * @Author: 中国赛宝 CEPREI
  * @Date:
  * @Version: 1.0.001
  * All rights reserved.
  *
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include <AT24Cxx.h>

/* Defines -------------------------------------------------------------------*/
#define EEPROM_IIC_ADDR       0x50      //IIC设备地址
#define EEPROM_SIZE           128>>3    //容量，单位kBit

/* Variables -----------------------------------------------------------------*/
uint16_t EEPROM_ChipId = 0;
uint8_t EEPROM_ReadBuff[32] = {0};
uint8_t EEPROM_WriteBuff[16] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
AT24Cxx eeprom(EEPROM_IIC_ADDR, EEPROM_SIZE);

/* Prototypes ----------------------------------------------------------------*/

/* Functions -----------------------------------------------------------------*/
/* 示例程序EEPROM初始化 */
void DemoEEPROMInit(void)
{  
  uint8_t i = 0;
  for(i=0;i<sizeof(EEPROM_WriteBuff);i++)
    eeprom.write(i,EEPROM_WriteBuff[i]);
}
/* DemoEEPROM读例程 */
void DemoEEPROM(void)
{
  uint8_t i = 0;
  Serial.print("eeprom地址0-32值:");
  Serial.print("\t");
  for(i=0;i<sizeof(EEPROM_ReadBuff);i++)
  {
    EEPROM_ReadBuff[i] = eeprom.read(i);
    Serial.print(EEPROM_ReadBuff[i], DEC);
  }
  Serial.println();
}

void setup() {
  Serial.begin(9600);
  DemoEEPROMInit();
}

void loop() {
  DemoEEPROM();
  delay(500);
}
